package com.cll.pmis.common.exception;

import com.cll.pmis.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author chenliangliang
 * @date 2018/6/25
 */
@Slf4j
@RestControllerAdvice
public class ExceptionHandler {


    @org.springframework.web.bind.annotation.ExceptionHandler(PmisException.class)
    public Result handlePmisException(PmisException e){
        log.warn("拦截到异常:{}",e.getMessage());
        return Result.fail(e.getMessage());
    }


    @org.springframework.web.bind.annotation.ExceptionHandler(ParamsException.class)
    public Result handleParamsException(ParamsException e){
        log.warn("拦截到参数异常:{}",e.getMessage());
        return Result.fail("参数异常："+e.getMessage());
    }

    @org.springframework.web.bind.annotation.ExceptionHandler(TransactionException.class)
    public Result handleTransactionException(TransactionException e){
        log.warn("拦截到事务异常:{}",e.getMessage());
        return Result.fail("事务异常："+e.getMessage());
    }

    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        log.error("拦截到未定义异常:{}",e.getMessage(),e);
        return Result.fail("服务器异常："+e.getMessage());
    }
}
